import dbus,gobject,time
from dbus.mainloop.glib import DBusGMainLoop

#DBusGMainLoop(set_as_default=True)

STATUS_OFFLINE = 1
STATUS_AVAILABLE = 2
STATUS_UNAVAILABLE = 3
STATUS_INVISIBLE = 4
STATUS_AWAY = 5
STATUS_EXTENDED_AWAY = 6
STATUS_MOBILE = 7
STATUS_TUNE = 8


def get_session_bus() :
  bus = dbus.SessionBus()
  return bus

def get_pidgin_object(object = None) :
  bus = get_session_bus()
  object = bus.get_object("im.pidgin.purple.PurpleService",
		"/im/pidgin/purple/PurpleObject")
  pidgin = dbus.Interface(object, "im.pidgin.purple.PurpleInterface")
  return pidgin
  

def set_new_status(pidgin, my_account  , message) :
	
  saved_status = pidgin.PurpleSavedstatusNew(message, STATUS_UNAVAILABLE)
  pidgin.PurpleSavedstatusSetMessage(saved_status, message)
  pidgin.PurpleSavedstatusActivateForAccount(saved_status, my_account)
  #pidgin.PurpleSavedstatusActivate(saved_status)


def main() :
  pidgin = get_pidgin_object()
  my_account = pidgin.PurpleAccountsFind("wearetherock@hotmail.com", "prpl-msn")

  believe = open("never_say_die.txt", "r")
  lines = believe.readlines()
  believe.close()

  while True :
	for line in lines :
	
	  message = line.rstrip().strip() #remove \n and surrounding space
	  if message != '' :
		set_new_status(pidgin, my_account, message)
		print message
	  time.sleep(10)
	  pidgin.PurpleSavedstatusDelete(message)
	
if __name__ == "__main__" :
  main()
  
  
#pidgin.PurpleAccountSetAlias(my_account, "What's your name?")
#pidgin.PurpleAccountSetUserInfo(my_account, "Just test ")
  
#loop = gobject.MainLoop()
#loop.run()

# remove \n : http://stackoverflow.com/questions/275018/how-can-i-remove-chomp-a-newline-in-python